#include "../tools.h"


class Solution {
public:
    /**
     * 
     * @param s string字符串 
     * @return int整型
     */
    unordered_map<char, int> dict = {
        {'I', 1},
        {'V', 5},
        {'X', 10},
        {'L', 50},
        {'C', 100},
        {'D', 500},
        {'M', 1000}
    };
    int romanToInt(string s) {
        int size = s.size();
        int res = 0;
        for(int i = 0; i < size; ++i){
            if(s[i] == 'I'){
                if(i + 1 < size && (s[i + 1] == 'V' || s[i + 1] == 'X')){
                    res += (dict[s[i + 1]] - dict[s[i]]);
                    ++i;
                    continue;
                }
            }
            if(s[i] == 'X'){
                if(i + 1 < size && (s[i + 1] == 'L' || s[i + 1] == 'C')){
                    res += (dict[s[i + 1]] - dict[s[i]]);
                    ++i;
                    continue;
                }
            }
            if(s[i] == 'C'){
                if(i + 1 < size && (s[i + 1] == 'D' || s[i + 1] == 'M')){
                    res += (dict[s[i + 1]] - dict[s[i]]);
                    ++i;
                    continue;
                }
            }
            res += dict[s[i]];
        }

        return res;
    }
};


int main(int argc, char const *argv[])
{
    Solution sol;

    string s = "IV";
    int res = sol.romanToInt(s);
    cout << res << endl;


    return 0;
}
